package com.plusjun.gulimall.product.web;

import com.plusjun.gulimall.product.entity.CategoryEntity;
import com.plusjun.gulimall.product.service.CategoryService;
import com.plusjun.gulimall.product.vo.Catalog2VO;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    @Resource
    private CategoryService categoryService;

    @GetMapping({"/","/index"})
    public String indexPage(Model model){

        List<CategoryEntity> categoryEntities = categoryService.getLevel1Categorys();
        model.addAttribute("categories",categoryEntities);
        return "index";
    }

    @GetMapping("/index/json/catalog.json")
    @ResponseBody
    public Map<String, List<Catalog2VO>> getCatelog2VO(){
        Map<String, List<Catalog2VO>> catelogJson = categoryService.getCatelog2VO();
        return catelogJson;
    }
}
